import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/1/30 11:32
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode head = new ListNode(1, new ListNode(0, new ListNode(1)));
        solution.getDecimalValue(head);
    }
    public int getDecimalValue(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        int ans = 0, size = list.size();
        for (int i = 0; i < size; i++) {
            if (list.get(i) == 1) {
                ans += Math.pow(2, size - i - 1);
            }
        }
        return ans;
    }

}
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}
